package com.woniuxy.intellihome.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.intellihome.entity.Category;
import com.woniuxy.intellihome.entity.GoodsSpu;
import com.woniuxy.intellihome.mapper.CategoryMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.intellihome.service.CategoryService;
import com.woniuxy.intellihome.service.GoodsSpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author HW 增加了一个方法查找Category(内含所属SPU) 08-13 16:39
 * @author jobob
 * @since 2021-08-11
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private GoodsSpuService spuService;

    @Override
    public List<Category> getByStatus() {
        return categoryMapper.getByStatus();
    }

    @Override
    public Category getCategoryAndItsSPU(int id) {
        GoodsSpu spu=new GoodsSpu();
        spu.setCategoryId(id);
        Wrapper<GoodsSpu> wrapper=new QueryWrapper<>(spu) ;
        List<GoodsSpu> spus = spuService.list(wrapper);

        Category category = categoryMapper.selectById(id);
        category.setSpus(spus);
        return category;
    }
}
